import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useUserStore = defineStore(
  'user',
  () => {
    const userInfo = ref([])
    const isLogined = ref(false)

    const setUserInfo = data => {
      userInfo.value = data
      isLogined.value = true
    }

    const logOut = () => {
      userInfo.value = []
      isLogined.value = false
    }
    const selectKey = ref(0)
    const setSelectKey = key => {
      selectKey.value = key
    }
    return { userInfo, isLogined, setUserInfo, logOut, selectKey, setSelectKey }
  },
  {
    // 持久化
    persist: {
      paths: ['userInfo', 'isLogined']
    }
  }
)
